﻿//-----------------------------------------------------------------
//
// @(#)$Id: OrderSplit.aspx.cs,v 1.0 2013/12/13 17:56:29 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:56:29 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ebay.Model;
using System.Web.UI.MobileControls;
using ebay.Dal;
using ebay.Dal.CenterDB_OrderTableAdapters;

public partial class UI_Orders_OrderSplit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string orderId = Request["orderId"];
            string ebayUserId = Request["ebayUserId"];

            if (!string.IsNullOrEmpty(orderId) && !string.IsNullOrEmpty(ebayUserId))
            {
                Bind(orderId, ebayUserId);
                txtEbayUserId.Value = ebayUserId;
                txtOrderId.Value = orderId;
            }
        }
    }

    void Bind(string orderId, string ebayUserId)
    {
        T_CustomerResolveContextTableAdapter cAdapter = new T_CustomerResolveContextTableAdapter();
        this.repeater1.DataSource = cAdapter.GetData(orderId, ebayUserId);
        repeater1.DataBind();
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        string mUser = Session["UserId"].ToString();
        List<SplitOrder> list1 = new List<SplitOrder>();
        List<SplitOrder> list2 = new List<SplitOrder>();
        for (int i = 0; i < repeater1.Items.Count; i++)
        {
            CheckBox chkBox = repeater1.Items[i].FindControl("chkitem") as CheckBox;
            bool select = chkBox.Checked;

            string orderLineItemId = (repeater1.Items[i].FindControl("orderLineItemId") as HtmlTableCell).InnerText;
            string productId = (repeater1.Items[i].FindControl("ProductId") as HtmlTableCell).InnerText;
            string ebayUserId = (repeater1.Items[i].FindControl("ebayUserId") as HtmlTableCell).InnerText;
            SplitOrder m = new SplitOrder();
            m.EbayUserId = ebayUserId;
            m.OrderLineItemId = orderLineItemId;
            m.ProductId = productId;
            if (select)
            {
                list1.Add(m);
            }
            else
            {
                list2.Add(m);
            }
        }
        if (list1.Count == 0 || list2.Count == 0)
        {
            WebUtility.ShowMsg("不能全部选择或者全不选", this);
        }
        else
        {

            Orders o = new Orders();
            bool val = o.SplitOrder(list1, list2, txtEbayUserId.Value, txtOrderId.Value, mUser);
            if (val)
            {
                Response.Write("<script>window.returnValue = true;window.close();</script>");
            }
            else
            {
                WebUtility.ShowMsg("拆分失败", this);
            }
        }
    }
}
